package com.jxsd.edu.cn.struts2.daoImpl;

import java.util.List;

import com.jxsd.edu.cn.struts2.dao.CatagoryDao;
import com.jxsd.edu.cn.struts2.models.Category;
import com.jxsd.edu.cn.tools.ResultBean;
import com.jxsd.edu.cn.tools.ResultList;
import com.jxsd.edu.cn.tools.Template;

public class CatagoryDaoImpl implements CatagoryDao {

	@Override
	public Category getCatagory(int  catagoryId) {
		Category  cata=null;
		Object[]  params={catagoryId};
		ResultBean<Category>  hander=new   ResultBean<Category>();
		String   sql="select  catagoryID,catagoryName  from  catagory  where  catagoryId=?";
		try {
			cata=hander.handler(sql, params, Category.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return cata;
	}

	@Override
	public List<Category> getCatagories() {
		List<Category>  list=null;
		Object[]  params=null;
		ResultList<Category>  hander=new   ResultList<Category>();
		String   sql="select  catagoryID,catagoryName  from  catagory";
		try {
			list=hander.handler(sql, params, Category.class);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	@Override
	public void deleteCatagory(int  catagoryId) {
		Object[]  params={catagoryId};
		String  sql="delete  from  catagory  where  catagoryId=?";
		Template  t=new  Template();
		t.update(sql, params);
	}

	@Override
	public void addCatagory(Category  catagory) {
		Object[]  params={catagory.getCatagoryID(),catagory.getCatagoryName()};
		String  sql="insert  into  catagory(catagoryId,catagoryName)  values(?,?)";
		Template  t=new  Template();
		t.update(sql, params);
	}
	
}
